home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 12.4 KB | 407 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // USynchScroller.cp
- // Copyright © 1989-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __USYNCHSCROLLER__
- #include "USynchScroller.h"
- #endif
-
- // MacApp
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UEVENT__
- #include "UEvent.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // InitUSynchScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollInit
-
- void InitUSynchScroller()
- {
- #if qTemplateViews
- // Suppress Linker dead-stripping of these classes
- MA_REGISTER_CLASS(TPrimaryScroller);
- MA_REGISTER_CLASS(TSecondaryScroller);
- #endif
- } // InitUSynchScroller
-
-
- //========================================================================================
- // CLASS TPrimaryScroller
- //========================================================================================
- #undef Inherited
- #define Inherited TScroller
-
- #pragma segment SyncScrollNonRes
- MA_DEFINE_CLASS_M1(TPrimaryScroller, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller constructor
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- TPrimaryScroller::TPrimaryScroller()
- {
- fSecondaryScrollers = NULL;
- } // TPrimaryScroller::TPrimaryScroller
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::IPrimaryScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- void TPrimaryScroller::IPrimaryScroller(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const VPoint& itsMax,
- Boolean wantHorzSBar,
- Boolean wantVertSBar)
-
- {
- this->IScroller(itsSuperView, itsLocation, itsSize,
- itsHSizeDet, itsVSizeDet, itsMax,wantHorzSBar, wantVertSBar);
- } // TPrimaryScroller::IPrimaryScroller
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- TPrimaryScroller::~TPrimaryScroller()
- {
- {
- CObjectIterator iter(fSecondaryScrollers);
- TSecondaryScroller* aSecondaryScroller;
-
- for (aSecondaryScroller = (TSecondaryScroller*) iter.FirstObject(); iter.More(); aSecondaryScroller = (TSecondaryScroller*) iter.NextObject())
- this->RemoveSecondaryScroller(aSecondaryScroller);
- }
- fSecondaryScrollers = (TList *)FreeIfObject(fSecondaryScrollers);
- } // TPrimaryScroller::Free
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::AddSecondaryScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- void TPrimaryScroller::AddSecondaryScroller(TSecondaryScroller* itsSecondaryScroller,
- VCoordinate itsHDependency,
- VCoordinate itsVDependency)
- {
- if (itsSecondaryScroller)
- {
- itsSecondaryScroller->fPrimaryScroller = this;
- itsSecondaryScroller->fDeltaFactor = VPoint(itsHDependency, itsVDependency).ToPoint();
-
- if (!fSecondaryScrollers)
- fSecondaryScrollers = NewList();
-
- fSecondaryScrollers->Insert(itsSecondaryScroller);
- }
- } // TPrimaryScroller::AddSecondaryScroller
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::RemoveSecondaryScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- void TPrimaryScroller::RemoveSecondaryScroller(TSecondaryScroller* itsSecondaryScroller)
- {
- if (itsSecondaryScroller)
- {
- itsSecondaryScroller->fPrimaryScroller = NULL;
- if (fSecondaryScrollers)
- {
- fSecondaryScrollers->Delete(itsSecondaryScroller);
- if (fSecondaryScrollers->IsEmpty())
- fSecondaryScrollers = (TList *)FreeIfObject(fSecondaryScrollers);
- }
- }
- } // TPrimaryScroller::RemoveSecondaryScroller
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::DoScroll:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollRes
-
- void TPrimaryScroller::DoScroll(const VPoint& delta,
- Boolean redraw)// override
- {
- {
- CObjectIterator iter(fSecondaryScrollers);
- TSecondaryScroller* aSecondaryScroller;
-
- for (aSecondaryScroller = (TSecondaryScroller*) iter.FirstObject(); iter.More(); aSecondaryScroller = (TSecondaryScroller*) iter.NextObject())
- {
- VPoint itsDelta(delta);
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- if (aSecondaryScroller->fDeltaFactor[vhs]) // kVDependent or kHDependent
- {
- if (itsDelta[vhs] < 0)
- {
- itsDelta[vhs] = Max(itsDelta[vhs], -aSecondaryScroller->fTranslation[vhs]);
- }
- else if (itsDelta[vhs] > 0)
- {
- itsDelta[vhs] = Min(itsDelta[vhs], aSecondaryScroller->fMaxTranslation[vhs] - aSecondaryScroller->fTranslation[vhs]);
- }
- aSecondaryScroller->fTranslation[vhs] += itsDelta[vhs];
- }
-
- if (itsDelta != gZeroVPt)
- {
- aSecondaryScroller->InvalidateFocus(); // You never know who might call
- aSecondaryScroller->InvalidateCoordinates();
- }
- }
- }
-
- Inherited::DoScroll(delta, redraw);
- } // TPrimaryScroller::DoScroll
-
- //----------------------------------------------------------------------------------------
- // TPrimaryScroller::ScrollDraw:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollRes
-
- void TPrimaryScroller::ScrollDraw(const VPoint& delta,
- Boolean invalidate)// override
- {
- if (fSuperView->IsDrawable())
- {
- CTemporaryRegion scrollRgn;
-
- this->GetExtentRegion(scrollRgn);
- this->LocalToSuperRegion(scrollRgn);
-
- CRect superVisRect((*GetClipRegion(qd.thePort))->rgnBBox); // just test the clip, it's faster
-
- #if qDebug
- if (gIntenseDebugging)
- WriteFocus();
- #endif
-
- const VRect visVRect(superVisRect);
- if (((visVRect - delta) & visVRect).Empty()) // too far to scrollrect
- {
- this->ForceRedraw();
-
- CObjectIterator iter(fSecondaryScrollers);
- TSecondaryScroller* aScroller;
-
- for (aScroller = (TSecondaryScroller*) iter.FirstObject(); iter.More(); aScroller = (TSecondaryScroller*) iter.NextObject())
- {
- if (aScroller->IsShown ())
- {
- if (delta.v && (aScroller->fDeltaFactor.v == kVDependent))
- aScroller->ForceRedraw();
- else if (delta.h && (aScroller->fDeltaFactor.h == kHDependent))
- aScroller->ForceRedraw();
- }
- }
- }
- else // Can use ScrollRect
- {
- CTemporaryRegion tempRgn;
-
- #if qDebug
- fSuperView->AssumeFocused();
- #endif
-
- { // for correct failure handling
- CObjectIterator iter(fSecondaryScrollers);
- TSecondaryScroller* aScroller;
-
- for (aScroller = (TSecondaryScroller*) iter.FirstObject(); iter.More(); aScroller = (TSecondaryScroller*) iter.NextObject())
- {
- if (aScroller->IsShown ())
- {
- CPoint localDeltaFactor(aScroller->fDeltaFactor);
-
- CRect frameRect(aScroller->fSuperView->ViewToQDRect(aScroller->GetFrame()));
- // main scroller is moving both directions but dependent can only move in v
- if (delta.h && delta.v && (localDeltaFactor.h == kNotHDependent) && (localDeltaFactor.v == kVDependent))
- {
- ScrollRect(frameRect, 0, (short) - delta.v, tempRgn);
- aScroller->fSuperView->InvalidateRegion(tempRgn);
- }
- // main scroller is moving both directions but dependent can only move in h
- else if (delta.h && delta.v && (localDeltaFactor.h == kHDependent) && (localDeltaFactor.v == kNotVDependent))
- {
- ScrollRect(frameRect, (short) - delta.h, 0, tempRgn);
- aScroller->fSuperView->InvalidateRegion(tempRgn);
- }
- // main scroller is moving in either direction and dependent can follow
- else if ((delta.h && (localDeltaFactor.h == kHDependent)) || (delta.v && (localDeltaFactor.v == kVDependent)))
- {
- aScroller->GetExtentRegion(tempRgn);
- aScroller->LocalToSuperRegion(tempRgn);
- UnionRgn(scrollRgn, tempRgn, scrollRgn);
- }
- }
- }
- }
-
- #if qDebug
- fSuperView->AssumeFocused();
- #endif
-
- // Now, we've either scrolled any dependent scrollers that can't scroll with
- // us or we've accumulated their frames in scrollRgn. By clipping to the
- // accumulated region we can just scroll the entire superview and the right
- // stuff should happen. (Cross fingers)
- SectRgn(scrollRgn, qd.thePort->clipRgn, scrollRgn);
-
- // Get clip so we can restore it later and keep from having
- // to invalidate the superview's focus
- GetClip(tempRgn);
-
- SetClip(scrollRgn);
- ScrollRect(superVisRect, (short) - delta.h, (short) - delta.v, scrollRgn);
-
- // restore the clip so we don't have to invalidate the focus
- SetClip(tempRgn);
-
- fSuperView->InvalidateRegion(scrollRgn);
- }
-
- if (!invalidate)
- fSuperView->Update();
- }
- } // TPrimaryScroller::ScrollDraw
-
-
-
- //========================================================================================
- // CLASS TSecondaryScroller
- //========================================================================================
- #undef Inherited
- #define Inherited TScroller
-
- #pragma segment SyncScrollNonRes
- MA_DEFINE_CLASS_M1(TSecondaryScroller, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSecondaryScroller constructor
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- TSecondaryScroller::TSecondaryScroller()
- {
- fPrimaryScroller = NULL;
- fDeltaFactor = CPoint(kNotHDependent, kNotVDependent);
- } // TSecondaryScroller::TSecondaryScroller
-
- //----------------------------------------------------------------------------------------
- // TSecondaryScroller::ISecondaryScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- void TSecondaryScroller::ISecondaryScroller(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const VPoint& itsMax,
- Boolean wantHorzSBar,
- Boolean wantVertSBar)
-
- {
- this->IScroller(itsSuperView, itsLocation, itsSize,
- itsHSizeDet, itsVSizeDet, itsMax,wantHorzSBar, wantVertSBar);
- } // TSecondaryScroller::ISecondaryScroller
-
- //----------------------------------------------------------------------------------------
- // TSecondaryScroller::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollNonRes
-
- TSecondaryScroller::~TSecondaryScroller()
-
- {
- if (fPrimaryScroller)
- fPrimaryScroller->RemoveSecondaryScroller(this); // sets fPrimaryScroller to NULL
- } // TSecondaryScroller::Free
-
- //----------------------------------------------------------------------------------------
- // TSecondaryScroller::DoScroll:
- //----------------------------------------------------------------------------------------
- #pragma segment SyncScrollRes
-
- void TSecondaryScroller::DoScroll(const VPoint& delta,
- Boolean redraw)// override
- {
- if (fPrimaryScroller)
- fPrimaryScroller->ScrollBy( VPoint( fDeltaFactor.h * delta.h, fDeltaFactor.v * delta.v), redraw);
- } // TSecondaryScroller::DoScroll
-
- //----------------------------------------------------------------------------------------
- // End of USynchScroller.cp
-
- #pragma segment Inline
-